#include <stdio.h>
#include <cstdlib>
#include <ctime>
#include "BalanceTree.h"

using namespace std;

int main()
{
	AvlTree<int> T1;
	SplayTree<int> T2;
	int num;

	cout << "Please enter the number of digit to be tested:" << endl;
	cin >> num;

	for (int i = 0; i < num; i++)
		T1.insert(rand());
	for (int i = 0; i < num; i++)
		T2.insert(rand());

	clock_t start1, end1;

	cout << "Avl Tree in sorted order:" << endl;
	start1 = clock();
	T1.printTree();
	cout << endl;
	end1 = clock();

	clock_t start2, end2;
	cout << "Splay Tree in sorted order:" << endl;
	start2 = clock();
	T2.printTree();
	cout << endl;
	end2 = clock();

	cout << "The efficiency of Avl Tree:";
	cout << (double)(end1 - start1) / CLOCKS_PER_SEC << endl;

	cout << "The efficiency of Splay Tree:";
	cout << (double)(end2 - start2) / CLOCKS_PER_SEC << endl;

	if (((double)(end1 - start1) / CLOCKS_PER_SEC) > ((double)(end2 - start2) / CLOCKS_PER_SEC))
		cout << "The efficiency of Splay Tree is higher than Avl Tree." << endl;

	if (((double)(end1 - start1) / CLOCKS_PER_SEC) < ((double)(end2 - start2) / CLOCKS_PER_SEC))
		cout << "The efficiency of Avl Tree is higher than Splay Tree." << endl;

	if (((double)(end1 - start1) / CLOCKS_PER_SEC) == ((double)(end2 - start2) / CLOCKS_PER_SEC))
		cout << "The efficiency of Avl Tree is same with the efficiency of Splay Tree." << endl;

	return 0;
}